﻿using Fuse8.DomainFramework.Common.Locator;

namespace Fuse8.DomainFramework.DataAccess.ExpressionSlicers
{
    /// <summary>
    /// Provides static properties for accessing slicer
    /// </summary>
    public static class SlicerServiceFacade
    {
        private static ISlicerService service;
        private static bool slicerSet;

        /// <summary>
        /// Current Slicer service
        /// </summary>
        public static ISlicerService Current
        {
            get
            {
                if (!slicerSet)
                {
                    service =
                        DependencyServiceLocator.Current.IsRegistered<ISlicerService>()
                            ? DependencyServiceLocator.Current.GetInstance<ISlicerService>()
                            : new DefaultSlicerService();
                    slicerSet = true;
                }

                return service;
            }
        }

        private static ISlicerScope scope;

        /// <summary>
        /// Current Slicer Scope manager
        /// </summary>
        public static ISlicerScope Scope
        {
            get
            {
                return scope ??
                       (scope =
                        DependencyServiceLocator.Current.IsRegistered<ISlicerScope>()
                            ? DependencyServiceLocator.Current.GetInstance<ISlicerScope>()
                            : new DefaultSlicerScope());
            }
        }

        /// <summary>
        /// Resets current settings
        /// </summary>
        public static void Reset()
        {
            slicerSet = false;
        }
    }
}